﻿<%@ Page Title="" Language="C#" MasterPageFile="~/pages/master/WebList.Master" AutoEventWireup="true"
    CodeBehind="TreeUserList.aspx.cs" Inherits="BF.Web.pages.BaseSystem.UserManagement.TreeUserList" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<%@ Register Src="/pages/UserControls/MultiComboBox.ascx" TagName="MultiComboBox"
    TagPrefix="uc1" %>
<%@ Register Src="../../UserControls/SysAreaTree.ascx" TagName="SysAreaTree" TagPrefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceJs" runat="server">
    <style type="text/css">
        .treePanlStyle
        {
            position: absolute;
            bottom: 0px;
            top: 0px;
            border: #99bbe8 1px solid;
            width: 270px;
            overflow: hidden;
        }
        #cmdctl00_ContentPlaceHtml_muljs_divComboBox
        {
            margin: 0px;
            height: 18px;
        }
        .auto-style1 {
            width: 100px;
            height: 25px;
        }
        .auto-style2 {
            width: 150px;
            height: 25px;
        }
        .auto-style3 {
            height: 25px;
        }
    </style>
    <script type="text/javascript">
        //操作处理
        var mytree;
        Ext.onReady(function () {
            mytree = new Ext.tree.TreePanel({
                el: "container", //应用到的html元素id
                animate: true, //以动画形式伸展,收缩子节点
                title: "机构管理",
                collapsible: false,
                titleCollapse: false,
                rootVisible: true, //是否显示根节点
                autoScroll: true,
                height: Ext.getBody().dom.clientHeight,
                bodyBorder: false,
                root: new Ext.tree.AsyncTreeNode({
                    id: "00000000-0000-0000-0000-000000000000",
                    text: "全部机构",
                    icon: "/images/icons/chart_organisation.png",
                    expanded: true
                }),
                border: false,
                lines: true, //节点之间连接的横竖线
                loader: new Ext.tree.TreeLoader({
                    dataUrl: "HHospitalTree.ashx?gKey=" + $("#<%=rootHospitalKey.ClientID %>").val(),
                    listeners: {
                        "loadexception": function (loader, node, response) {
                        }
                    }
                }),
                layout: 'fit'
            });
            mytree.render();
            mytree.on('click', function (node) {
                node.expand();
                if (node.attributes.gKey == undefined && "<%=ISWSJ %>" == "FALSE") { return; }
                if (node.attributes.gKey == undefined) {
                    $("#ctl00_ContentPlaceHtml_gTreeHospitalKey").val(node.id);
                } else {
                    $("#ctl00_ContentPlaceHtml_gTreeHospitalKey").val(node.attributes.gKey);
                }
                //根节点 禁用新增按纽
                if (node.isRoot) { $("#ctl00_ContentPlaceHtml_btnAdd,#ctl00_ContentPlaceHtml_btnAdd img,#ctl00_ContentPlaceHtml_LinkButton1,#ctl00_ContentPlaceHtml_LinkButton1 img").attr("disabled", true); }
                else { $("#ctl00_ContentPlaceHtml_btnAdd,#ctl00_ContentPlaceHtml_btnAdd img,#ctl00_ContentPlaceHtml_LinkButton1,#ctl00_ContentPlaceHtml_LinkButton1 img").removeAttr("disabled"); }
                __doPostBack('ctl00$ContentPlaceHtml$AspNetPager1', '');
            });

            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () {
                var tmp = Ext.get('ctl00_ContentPlaceHtml_AspNetPager1');
                tmp.dom.style.width = Ext.getBody().dom.clientWidth - 271;
            });

            mytree.syncSize();
            var tmp = Ext.get('container');
            tmp.dom.onresize = function () {
                mytree.syncSize();
                var tmp2;
                tmp2 = Ext.get('ctl00_ContentPlaceHtml_AspNetPager1');
                tmp2.setWidth(Ext.getBody().dom.clientWidth - 271);
            }
        });
    </script>
    <script type="text/javascript" language="javascript">

        function OpenRolesPlan() {
            var count = 0;
            var UserArray = new Array();
            $("input[name*='Repeater1']").each(function () {
                if (this.checked) {
                    UserArray.push(this.defaultValue);
                    ++count;
                }
            });
            if (count == 0) {
                Ext.MessageBox.show({ title: '提示', msg: '请选择需要绑定角色的用户！', buttons: { ok: '确  定' }, icon: 'ext-mb-info' });
                return false;
            }
            var jsonStirng = Ext.encode(UserArray);
            $("#ctl00_ContentPlaceHtml_hidModifyUserID").val(jsonStirng);
            winer.OpenWin('用户角色绑定', GetUrl(this) + 'UserModifyRoles.aspx', 600, 410, false, this);
            return false;
        }


        $(function () {
            $("#tbList").find("tr:gt(0)").each(function () {
                if ($(this).find("td:eq(0)").find("input[name*='chksuserid']").attr("accessKey") == "False") {
                    $(this).find("td").each(function () {
                        $(this).css("color", "#FF0000");
                    });
                }
            });

            //异步刷新回发事件
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () {
                $("#tbList").find("tr:gt(0)").each(function () {
                    if ($(this).find("td:eq(0)").find("input[name*='chksuserid']").attr("accessKey") == "False") {
                        $(this).find("td").each(function () {
                            $(this).css("color", "#FF0000");
                        });
                    }
                });
            });

        });

        function MultipleSelect(obj) {
            if (obj.checked) {
                $("#div_scroll_x  :checkbox").attr("checked", true);
            }
            else {
                $("#div_scroll_x :checkbox:checked").each(function () {
                    $(this).attr("checked", false);
                })
            }
        }

        //控制checkbox在单选模式时，只能单选
        function Controlcheck(obj) {
            if (!$("#chxIsMultipleSelect").attr("checked")) {
                if (obj.checked) {
                    $("#div_scroll_x  :checkbox:checked").not(obj).attr("checked", false);
                }
            }
        }

        function Add() {
                var gTreeHosKey = $("#ctl00_ContentPlaceHtml_gTreeHospitalKey").val();
                if (gTreeHosKey == null || gTreeHosKey == "") {
                    Ext.MessageBox.show({ title: '提示', msg: '请选择要新增人员信息的机构！', buttons: { ok: '确  定' }, icon: 'ext-mb-info' });
                }
                else {
                    winer.OpenWin('新增用户信息', GetUrl(this) + 'UserEdit.aspx?gTreeHospitalKey=' + gTreeHosKey, 600, 410, false, this);
                }
           
            return false;
        }

        function Delete() {
            var values = "";
            var count = 0;
            var humanState;
            $("input[name*='Repeater1']").each(function () {
                if (this.checked) {
                    $this = $(this);
                    values = this.defaultValue;
                    humanState = $this.attr("humanstate");
                    ++count;
                }
            });
            if (count == 0) {
                Ext.MessageBox.show({ title: '删除提示', msg: '请选择需要删除的记录!', buttons: { ok: '确  定' }, icon: 'ext-mb-info' });
                return false;
            }
            else {
                var delMsg = "是否确认删除选中的记录？";
                if (humanState == 1) {
                    delMsg = "该信息存在人力资源信息关联，是否确认删除？";
                }
                Ext.MessageBox.show({
                    title: '删除提示',
                    msg: delMsg,
                    buttons: { yes: '确  定', no: '取 消' },
                    fn: function (result) {
                        if (result == "yes") {
                            __doPostBack("ctl00$ContentPlaceHtml$lbtnDelete", "");
                        }
                    },
                    icon: 'ext-mb-info'
                });
                return false;
            }
        }

        function Update() {
            var values = "";
            var count = 0;
            $("input[name*='Repeater1']").each(function () {
                if (this.checked) {
                    values = this.defaultValue;
                    ++count;
                }
            });
            var gTreeHosKey = $("#ctl00_ContentPlaceHtml_gTreeHospitalKey").val();
            if (gTreeHosKey == null || gTreeHosKey == "") {
                Ext.MessageBox.show({ title: '提示', msg: '请选择要修改人员信息的机构！', buttons: { ok: '确  定' }, icon: 'ext-mb-info' });
                return false;
            }
            if (count != 1) {
                Ext.MessageBox.show({ title: '修改提示', msg: '请选择需要编辑的记录,并且只能选择一项！', buttons: { ok: '确  定' }, icon: 'ext-mb-info' });
                return false;
            }
            winer.OpenWin('用户信息修改', GetUrl(this) + 'UserEdit.aspx?sKey=' + values + '&gTreeHospitalKey=' + gTreeHosKey, 600, 410, false, this);
            return false;
        }

        //停用
        var titleStop = "提示";
        var msgStop = "请选择要停用的记录";
        var configStop = "是否确认要停用记录？";
        function Stop() {
            var isDelete = $("#div_scroll_x :checkbox:checked");
            if (isDelete.length == 0) {
                Ext.MessageBox.show({ title: titleStop, msg: msgStop, buttons: { ok: '确  定' }, icon: 'ext-mb-info' });
                return false;
            }
            else {
                Ext.MessageBox.show({
                    title: titleStop,
                    msg: configStop,
                    buttons: { yes: '确  定', no: '取 消' },
                    fn: function (result) {
                        if (result == "yes") {
                            __doPostBack("ctl00$ContentPlaceHtml$lbtnStop", "");
                        }
                    },
                    icon: 'ext-mb-info'
                });
                return false;
            }
        }

        function checkStop(obj) {
            Controlcheck(obj);
            var state = "";
            $("#div_scroll_x :checkbox:checked").each(function () {
                state += $(this).attr("accesskey") + "#";
            })

            //停用启用状态
            var state = "";
            $("#div_scroll_x :checkbox:checked").each(function () {
                state += $(this).attr("accesskey") + "#";
            })

            if (state.indexOf("False#True#") != -1 || state.indexOf("True#False#") != -1) {
                $("#ctl00_ContentPlaceHtml_lbtnStop").attr("disabled", "disabled");
                $("#ctl00_ContentPlaceHtml_lbtnStop").attr("href", "javascript:void(0);");
                return false;
            }
            if (state.indexOf("False#") != -1) {
                $("#ctl00_ContentPlaceHtml_hideStop").val("1");
                $("#ctl00_ContentPlaceHtml_lbtnStop").attr("disabled", "");
                $("#ctl00_ContentPlaceHtml_lbtnStop").attr("href", " javascript: __doPostBack('ctl00$ContentPlaceHtml$lbtnStop', '')")
                $('#divStop').html('启用');

                titleStop = "提示";
                msgStop = "请选择要启用的记录！";
                configStop = "是否确认要启用记录？";
                return false;
            }
            if (state.indexOf("True#") != -1) {
                $("#ctl00_ContentPlaceHtml_hideStop").val("0");
                $("#ctl00_ContentPlaceHtml_lbtnStop").attr("disabled", "");
                $('#divStop').html('停用');
                $("#ctl00_ContentPlaceHtml_lbtnStop").attr("href", " javascript: __doPostBack('ctl00$ContentPlaceHtml$lbtnStop', '')")
                titleStop = "提示";
                msgStop = "请选择要停用的记录！";
                configStop = "是否确认停用记录？";
                return false;
            }

        }

        //查看角色信息
        function View(gUserID) {
            winer.OpenWin('用户信息查看', GetUrl(this) + 'UserEdit.aspx?State=View&skey=' + gUserID, 600, 410, false, this);
            return false;
        }

        //关闭弹出window时，执行的事件
        function Refurbish() {
            __doPostBack('ctl00$ContentPlaceHtml$AspNetPager1', '');
        }

        //批量授权窗口
        function Authorize() {
            winer.OpenWin('用户角色批量授权', GetUrl(this) + 'VolumeLicensingMsg.aspx', 600, 410, false, this);
            return false;
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHtml" runat="server">
    <!--当前可操作机构的根节点-->
    <asp:HiddenField ID="rootHospitalKey" runat="server" />
    <!--选中的机构Key-->
    <asp:HiddenField ID="gTreeHospitalKey" runat="server" />
    <!--选中用于修改绑定角色的用户-->
    <asp:HiddenField ID="hidModifyUserID" runat="server" />
    <div id="container" class="treePanlStyle">
    </div>
    <table id="tabHead" width="100%" border="0" align="center" cellpadding="0" cellspacing="0"
        class="listtop1" style="position: absolute; left: 271px; top: 0px; right: 0px;">
        <tr>
            <td id="QueryCondition" style="border-bottom: 1px solid #8db2e3;">
                <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-bottom: 5px;
                    margin-top: 4px;" class="content04 ">
                    <tr>
                        <td align="right" class="auto-style1">
                            用户编号：
                        </td>
                        <td class="auto-style2">
                            <tll:DataTextBox ID="sLoginName" runat="server"></tll:DataTextBox>
                        </td>
                        <td align="right" class="auto-style1">
                            用户名：
                        </td>
                        <td class="auto-style2">
                            <tll:DataTextBox ID="sUserName" runat="server"></tll:DataTextBox>
                        </td>
                        <td class="auto-style3">
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            用户角色：
                        </td>
                        <td>
                            <uc1:MultiComboBox ID="muljs" Width="135" ListWidth="300" Columns="2" runat="server" />
                        </td>
                        <td align="right">
                            状态：
                        </td>
                        <td>
                            <asp:DropDownList runat="server" ID="ddlState" Width="136">
                                <asp:ListItem Selected="True" Value="1">启用</asp:ListItem>
                                <asp:ListItem Value="0">停用</asp:ListItem>
                                <asp:ListItem Value="2">所有</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                        <td>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <table id="" width="100%" border="0" align="center" cellpadding="0" cellspacing="0"
                    style="margin-bottom: 2px; margin-top: 2px; height: 26px;">
                    <tr>
                        <td>
                            <div class="btn01">
                                <asp:LinkButton ID="lbtnQuery" runat="server" OnClick="lbtnQuery_Click">
                            <span>
                                <img alt="" src="http://extjs.com/s.gif" border="0" class="icon icon-magnifier" /><div class="center">
                                    查询</div>
                            </span>
                                </asp:LinkButton>
                                <asp:LinkButton ID="btnAdd" runat="server" OnClientClick="return Add();">
                            <span>
                                <img src="../../../images/table_add.png" alt="" border="0" /><div class="center">
                                    新增</div>
                            </span>
                                </asp:LinkButton>
                                <asp:LinkButton ID="btnUpdate" OnClientClick="return Update();" runat="server">
                            <span>
                                <img src="../../../images/table_edit.png" alt="" border="0" /><div class="center">
                                    修改</div>
                            </span>
                                </asp:LinkButton>
                                <asp:LinkButton ID="lbtnDelete" runat="server" OnClientClick="return Delete();" OnClick="lbtnDelete_Click">
                            <span>
                                <img src="../../../images/table_delete.png" alt="" border="0" /><div class="center">
                                    删除</div>
                            </span>
                                </asp:LinkButton>
                                <asp:LinkButton ID="lbtnStop" runat="server" OnClientClick="return Stop();" OnClick="lbtnStop_Click">
                        <span>
                            <img src="../../../images/table_delete.png" alt="" border="0" /><div class="center" id="divStop">
                                停用</div>
                        </span>
                                </asp:LinkButton>
                                <%-- 1：启用 0：停用--%>
                                <asp:HiddenField ID="hideStop" runat="server" Value="0" />
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <div id="div_scroll_x" class="div_scroll" style="position: absolute; left: 274px;
        width: auto; right: 0px;">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Repeater ID="Repeater1" runat="server">
                    <HeaderTemplate>
                        <table id="tbList" width="100%" border="0" align="center" cellpadding="0" cellspacing="0"
                            class="list">
                            <thead>
                                <tr>
                                    <td align="center" style="width: 32px; padding-left: 5px;">
                                        <input id="chxIsMultipleSelect" type="checkbox" onclick="MultipleSelect(this)" />
                                    </td>
                                    <td align="left" style="width: 100px;">
                                        用户编号
                                    </td>
                                    <td align="left" style="width: 100px;">
                                        用户名
                                    </td>
                                    <td align="left" style="width: 250px;">
                                        组织机构名称
                                    </td>
                                    <td align="left" style="width: 170px;">
                                        所属地区
                                    </td>
                                    <td align="left" style="width: 70px;">
                                        有效标识
                                    </td>
                                    <td>
                                    </td>
                                </tr>
                            </thead>
                            <tbody>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr>
                            <td align="center">
                                <input type="checkbox" name="checkbox1" id="chksuserid" runat="server" value='<%#Eval("gUserID")%>'
                                    onclick="checkStop(this);" accesskey='<%#Eval("iState") %>' />
                                <input type="hidden" name="sLoginName" id="sLoginName" runat="server" value='<%#Eval("sLoginName")%>' />
                            </td>
                            <td align="left">
                                <div class="divnr-auto" title='<%#Eval("sLoginName")%>'>
                                    <a href="#" onclick="View('<%#Eval("gUserID")%>')">
                                        <%#Eval("sLoginName")%></a></div>
                            </td>
                            <td align="left">
                                <div class="divnr-auto" title='<%#Eval("sLoginName")%>'>
                                    <%#Eval("sUserName")%></div>
                            </td>
                            <td align="left">
                                <div class="divnr-auto" title='<%#Eval("sOrganizationName")%>'>
                                    <%#Eval("sOrganizationName")%></div>
                            </td>
                            <td align="left">
                                <div class="divnr-auto" title='<%#Eval("sAreaName")%>'>
                                    <%#Eval("sAreaName")%></div>
                            </td>
                            <td align="center">
                                <div class="divnr-auto" title='<%#Eval("iStateText")%>'>
                                    <%#Eval("iStateText")%></div>
                            </td>
                            <td>
                            </td>
                        </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                        </tbody> </table>
                    </FooterTemplate>
                </asp:Repeater>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="lbtnQuery" EventName="Click" />
                <asp:AsyncPostBackTrigger ControlID="AspNetPager1" EventName="PageChanged" />
                <asp:AsyncPostBackTrigger ControlID="lbtnDelete" EventName="Click" />
                <asp:AsyncPostBackTrigger ControlID="lbtnStop" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
    <div class="div_AspNetPager" style="position: absolute; left: 271px; width: auto;
        right: 0px;">
        <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="fengye">
                    <tr>
                        <td>
                            <webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged"
                                meta:resourcekey="AspNetPager1" PageSize="15" SkinID="AspNetPager">
                            </webdiyer:AspNetPager>
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="lbtnQuery" EventName="Click" />
                <asp:AsyncPostBackTrigger ControlID="lbtnDelete" EventName="Click" />
                <asp:AsyncPostBackTrigger ControlID="lbtnStop" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
</asp:Content>
